package com.wangwei.sort;

/**
 * 插入排序
 */
public class Insertion extends Example{

    @Override
    public void sort(Comparable[] arr){
        for(int i = 1; i <arr.length;i++){
            for(int j=i;j>0 && less(arr[j],arr[j-1]);j--)
                exch(arr,j,j-1);
        }
    }

    public static void main(String[] args) {
        String [] arr = {"A","S","D","F","G","H","J","K","L"};
        Example example = new Insertion();

        example.sort(arr);
        assert example.isSorted(arr);
        example.show(arr);
    }
}
